package e_routing_topic;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;
import utils.RabbitMQUtils;

public class Producer {
    @Test
    public void sendMessage() throws Exception {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        String exchangeName = "topic";
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.TOPIC);

        channel.basicPublish(exchangeName, "user", null, ("我是一个 topic 类型的交换机消息-routingKey:" + "user").getBytes());
        channel.basicPublish(exchangeName, "user.insert", null, ("我是一个 topic 类型的交换机消息-routingKey:" + "user.insert").getBytes());
        channel.basicPublish(exchangeName, "user.insert.a", null, ("我是一个 topic 类型的交换机消息-routingKey:" + "user.insert.a").getBytes());

        System.out.println("消息发送成功");
        RabbitMQUtils.closeChannelAndConnection(channel, connection);
    }
}